using System;
using System.Collections.Generic;

namespace InfiniTec.Threading
{
    class OperationInfo
    {
        private readonly AsyncOperation _Operation;
        private readonly List<Type> _ExceptionsToHandle;

        public AsyncOperation Operation { get { return _Operation; } }
        
        public bool HandlesException(Exception exception)
        {
        	if (exception == null) throw new ArgumentNullException("exception");

        	foreach (Type type in _ExceptionsToHandle)
            {
                if (exception.GetType().IsAssignableFrom(type)) return true;
            }
            return false;
        }

        public OperationInfo(AsyncOperation operation, List<Type> exceptionsToHandle)
        {
            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }
            if (exceptionsToHandle == null)
            {
                throw new ArgumentNullException("exceptionsToHandle");
            }
            _Operation = operation;
            _ExceptionsToHandle = exceptionsToHandle;
        }

    }
}
